/*
 * @brief :   
 * @date :  2022-02-xx
 * @version : v1.0.0
 * @copyright(c) 2020 : OptoMedic company Co.,Ltd. All rights reserved
 * @Change Logs:   
 * @date         author         notes:  
 */
#include "locker_pthread.h"
#include "pthread.h"


static int pthread_lock_func(locker_t *lk)  
{
    pthread_mutex_t *mutex = (pthread_mutex_t *)lk->private_data;
    return  pthread_mutex_lock(mutex);
}

static int pthread_unlock_func(locker_t *lk)  
{
    pthread_mutex_t *mutex = (pthread_mutex_t *)lk->private_data;
    return  pthread_mutex_unlock(mutex);
}   

static int pthread_destroy_func(locker_t *lk)  
{
    pthread_mutex_t *mutex = (pthread_mutex_t *)lk->private_data;
    return  pthread_mutex_destroy(mutex);
}

locker_t *locker_pthread_create(void)
{
    locker_t *thiz = (locker_t *) malloc(sizeof(locker_t));
    if (thiz == NULL) return NULL;

    thiz->private_data = malloc(sizeof(pthread_mutex_t));
    if (thiz->private_data == NULL) return NULL;

    thiz->lock = pthread_lock_func;
    thiz->unlock = pthread_unlock_func
    thiz->destroy = pthread_destroy_func;

    pthread_mutex_init((pthread_mutex_t *)thiz->private_data);
}